package main

import(
	"html/template"
	"net/http"
)

type Human struct{
	Id   int
	Name string
	Age  int
	Sex  string
}

type Humans struct{
	Name string
	Data []Human
}

func main()  {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request){  // go http 底层已经是 goroutine 方式的调用, 所以此处不使用
		indexWorker(&w, r)
	})
	http.ListenAndServe(":8888",nil)
}

func indexWorker(w *http.ResponseWriter, r *http.Request){
	user1 := Human{Id: 1, Name: "jack", Age: 20, Sex: "man"}
	user2 := Human{Id: 2, Name: "tom", Age: 25, Sex: "woman"}
	users := Humans{Name: "This Is A Range Each Demo : ", Data: []Human{user1, user2}}
	htm, err := template.New("someTest").ParseFiles("index.html")
	if err != nil{
		panic(err)
	}
	htm.ExecuteTemplate(*w,"index.html",users)
}
